package com.xuanwei.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.xuanwei.core.response.ResultVO;
import com.xuanwei.core.service.IXwFindContentService;
import com.xuanwei.dao.entity.XwFindContent;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;


/**
 * @Author jiangyong
 * @Description TODO
 * @Date 2019/8/7 17:48
 **/
@RestController
@RequestMapping("/api/findContent")
@Validated
public class FindContentController extends BasicController {

    private IXwFindContentService findContentService;

    public FindContentController(IXwFindContentService findContentService) {
        this.findContentService = findContentService;
    }

    @RequestMapping(value = "add.do", method = RequestMethod.POST)
    public ResultVO add(Integer id, @NotBlank(message = "内容不能为空") String content,
                        @NotBlank(message = "图片不能为空") String images,
                        @RequestParam(defaultValue = "0") Integer orderBy) {
        findContentService.add(id, content, images, orderBy);

        return ResultVO.successResult("保存成功");
    }

    @RequestMapping(value = "list.do", method = RequestMethod.GET)
    public ResultVO list() {
        Page<XwFindContent> page = getPage();
        findContentService.findPage(page);
        return ResultVO.successResult(page);
    }

    @RequestMapping(value = "delete.do", method = RequestMethod.GET)
    public ResultVO del(@Min(value = 1, message = "ID格式错误") Integer id) {
        findContentService.del(id);
        return ResultVO.successResult("删除成功");
    }


}
